/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
#if _LOCALDB
  using Oceanside.LocalDB;
#else
using Oceanside.RemoteDB;
#endif
namespace Oceanside
{
    public class UMD : INotifyError
    {
       INotifyError LogNotifyDispatcher = new ED();

        private static CircularProgressBar _cpb;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="progressBar"></param>
        public UMD(CircularProgressBar progressBar)
        {
            _cpb = progressBar;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="main"></param>
        private delegate void ShowErrorMessageDelegateType(string message);
        public static void ShowGuiMessageSTASafe_NOTHROW(string message)
        {
            try
            {
                if (Constants.MainDispatcher != null)
                {
                    if (Constants.MainDispatcher.CheckAccess())
                    {
                        Oceanside.MessageBox mb = new MessageBox(message);
                        Oceanside.MainWindow.ProgressCircle.StopStoryboard_NOTHROW();
                        mb.ShowDialog();
                    }
                    else
                    {
                        Constants.MainDispatcher.Invoke(new ShowErrorMessageDelegateType(ShowGuiMessageSTASafe_NOTHROW), message);
                    }
                }
            }
            catch (System.Exception exc)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_POSWINDOW_SHOW_MESSAGE_THRDSAFE, exc);
            }
        }

        private delegate void NotifyDelegateType(Error.EType error, Exception e, object[] extraParams = null);

        /// <summary>
        /// This function absolutely in no way shape or form can throw and exception as it is used to handle
        /// exceptions.  This means that we should not try to log an exception that occurs when this function
        /// is in motion because we are already in the middle of an exception as it is.
        /// </summary>
        /// <param name="error">The error number that occurred.</param>
        /// <param name="e">The exception that occurred at the callers location.</param>
        public void Notify(Error.EType error, Exception e, object[] extraParams = null)
        {
            string message = null;
            if (!Constants.MainDispatcher.CheckAccess())
            {
                Constants.MainDispatcher.Invoke(new NotifyDelegateType(Notify), error, e, extraParams);
            }
            else
            {
                try
                {
                    ///First assure that the error is logged.
                    LogNotifyDispatcher.Notify(error, e);

                    ///Make sure the storyboard stops running.
                    if (_cpb != null)
                    {
                        _cpb.StopStoryboard_NOTHROW();
                    }

                    ///Now process the error for this dispatcher type.  Many of these errors only require
                    ///that we log the message to the log file.  There are tons of safety nets that are
                    ///overkill and more than likely will never occur and there is nothing
                    ///we can do about some of them.  In those cases, the call at the start of this function
                    ///will log the error to file and we will simply pass through the switch.
                    switch (error)
                    {
                        /// <summary>
                        /// All occur inside of App.cs
                        /// </summary>
                        case Error.EType.E_APP_FINALIZE_STARTUP:
                            {
                                UMD.ShowGuiMessageSTASafe_NOTHROW("A critical and unexpected error has occurred during startup.  The cause could be related to hardware or network connectivity issues.  Press OK and the application will attempt to restart.");
                                System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
                                si.WorkingDirectory = Constants.RELAUNCH_DIRECTORY;
                                si.FileName = Constants.RELAUNCH_DIR_AND_PROGRAM;
                                System.Diagnostics.Process.Start(si);
                                Environment.Exit(0);
                                break;
                            }
                        case Error.EType.E_APP_REUPDATED_DB_CONTEXT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system could not update the local configuration that is required after a system update or menu change event has occurred.  When you attempt to use functions that require the missing data, you will be presented with more options to resolve this issue.");
                            break;
                        case Error.EType.E_APP_MAIN_UNCAUGHT_EXCEPTION:
                            {
                                UMD.ShowGuiMessageSTASafe_NOTHROW("A critical and unexpected error has occurred.  The cause could be related to hardware or network connectivity issues.  Press OK and the application will attempt to restart.");
                                System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
                                si.WorkingDirectory = Constants.RELAUNCH_DIRECTORY;
                                si.FileName = Constants.RELAUNCH_DIR_AND_PROGRAM;
                                System.Diagnostics.Process.Start(si);
                                Environment.Exit(0);
                                break;
                            }
                        case Error.EType.E_CCBIND_CLOSE_TABLE_TASK:
                            ///If the database connection is in fact lost, we will hit this error.  
                            ///At this point, if the database is not available the user can retry
                            ///the same operation without issue.  However we need to think about 
                            ///switching to a new database connection.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was not able to completely close the table due to a loss in database connectivity.  The cause of this issue is likely an unresponsive database server.  Please retry closing the table or wait until the database server becomes responsive.  Do not reboot this machine until this table has been completely closed out or a loss in data could occur.");
                            break;
                        case Error.EType.E_CCBIND_COMP_PERCENT_OR_AMOUNT_WIN_CLOSE_CB:
                            ///A lot could happen here.  The worst case scenario is that we cannot
                            ///comp the amount.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to perform the compensation action that you requested.");
                            break;
                        case Error.EType.E_CCBIND_SPLIT_CHECK_HOW_MANY_CB:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to split this particular payment using the type of split operation that you requested.");
                            break;
                        case Error.EType.E_CCBIND_CASH_PAY_CALLBACK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to add a cash payment to the selected check.  Please try to add a cash payment again.");
                            break;
                        case Error.EType.E_CCBIND_CALL_CASHPAY:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_COMPAMOUNT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_COMPPAYMENT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_COMPPRODUCT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_DELETE_TABLE:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_EQUALPAY:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_EXIT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_PRINTCCRECEIPT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_PRINTITEMRECEIPT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_PRINTTOTALRECEIPT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_SCROLLCHECKDOWN:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_SCROLLCHECKUP:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_SHOWKEYBOARD:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CCBIND_CALL_POP_USERS_DRAWER:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An attempt to open the cash drawer has failed.  If this system does not have a cash drawer attached please update this KIOSK's configuration in the back office.\n\nOtherwise check the connection to the local printer as well as the connection from the printer to the cash drawer.  A printer reboot may be required.  In emergency cases, contact your manager to obtain a physical key to the cash drawer lock in order to open the cash drawer.");
                            break;

                        /// <summary>
                        /// All occur inside the bindings for the control panel window.
                        /// </summary>
                        case Error.EType.E_CPBIND_CALL_BOUND_FUNC:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CPBIND_PREPARE_FOR_SCREEN_CHANGE:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CPBIND_BLINK_TABLES_ON_HOLD_TIMER_TICK:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CPBIND_OPEN_TABLES_SELECTION_CHANGED:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CPBIND_CANCEL_BUTTON_MOUSE_DOWN:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CPBIND_DOWN_ARROW_MOUSE_DOWN:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_CPBIND_UP_ARROW_MOUSE_DOWN:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;

                        /// <summary>
                        /// These errors are used around the program.  They are based on legacy code
                        /// and just got slapped into one file.
                        /// </summary>
                        case Error.EType.E_GEN_CREDIT_CARD_GATEWAY_RESPONSE_DELEGATE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to process the card that you attempted to use.  Please try again.");
                            break;

                        /// <summary>
                        /// These errors occur in the list view page or the page that displays most of the financial
                        /// functions such as employee checkout.
                        /// </summary>
                        case Error.EType.E_LVBBIND_USER_CHECKOUT_DB:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to checkout the current user.  Please try to perform the operation again.  We sincerely apologize for any inconvenience this may have caused and value your trust and time.");
                            break;
                        case Error.EType.E_LVBBIND_EMULATE_CAPTURE_ALL:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("While the point of sale system was communicating with the remote payment processor an unexpected error condition was encountered.  This means that there is a possibility that some or all of the transactions that you attempted to capture are still pending with an authorized status.  You can try the operation again, or call your payment processor to assure that they have been captured or have them capture the transactions for you.");
                            break;
                        case Error.EType.E_LVBIND_CREATE_DIFF_DATA_AND_CAPT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("While the point of sale system was communicating with the remote payment processor an unexpected error condition was encountered.  This means that there is a possibility that some or all of the transactions that you attempted to capture are still pending with an authorized status.  You can try the operation again, or call your payment processor to assure that they have been captured or have them capture the transactions for you.");
                            break;
                        case Error.EType.E_LVBIND_CALL_CAPTURE_ALL:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_LVBIND_CALL_CAPTURE_SINGLE:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_LVBIND_CALL_CASHIER_CHECKOUT:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_LVBIND_CALL_CREDIT_CARD_TIPS:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_LVBIND_CALL_RETURN:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_LVBIND_CALL_SEARCH_TRANSACTION:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_SELL_NONMENU:
                            ///Should be a development only error.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_CLOSECHECK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        /// <summary>
                        /// Errors that can occur on the place an order page.
                        /// </summary>
                        case Error.EType.E_POBIND_REPEAT_PROD_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_SUBMENU_BUTTON_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_MAIN_MENU_SCROLL_DOWN:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_SUB_MENU_SCROLL_UP:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_SUB_MENU_SCROLL_DOWN:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_SCROLL_SEAT_LEFT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_SCROLL_SEAT_RIGHT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_SEAT_BUTTON_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_MAIN_MENU_BUTTON_CLICKED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_MAIN_MENU_SCROLL_UP:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CUST_TICKET_SELECTION_CHANGED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_PREPARE_FOR_SCREEN_CHANGE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_MENU_CHANGED:
                            {
                                UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to update the product menu.  This is a critical error and will prevent any products from being selected from the menu.  The application will now restart in an attempt to resolve the issue.");
                                System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
                                si.WorkingDirectory = Constants.RELAUNCH_DIRECTORY;
                                si.FileName = Constants.RELAUNCH_DIR_AND_PROGRAM;
                                System.Diagnostics.Process.Start(si);
                                Environment.Exit(0);
                            }
                            break;
                        case Error.EType.E_POBIND_CALL_ASAPPET:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_BARSEAT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_CLEAR:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_CLONEPRODUCT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_CONTROLPANEL:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_CUSTOMERNAME:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_DELETE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_DELIVERY:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_DONE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_DONTMAKE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_ENTERQUANTITY:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_EXCPMODIFIY:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_HOLD:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_NEWSEAT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_NEWTABLE_PO:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_PRINTBARSLIP:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_SCROLLTICKETDWN:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_SCROLLTICKETUP:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_SPLITCHECK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_SPLITSEAT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_SUBMITORDER:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_POBIND_CALL_TAKEOUT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;


                        /// <summary>
                        /// Errors that can occur when trying to split the items on a seat
                        /// or a check.
                        /// </summary>
                        case Error.EType.E_SPLITBIND_SCROLL_SEAT_LEFT2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_SEAT_LEFT1:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_SEAT_RIGHT2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_SEAT_RIGHT1:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SEAT_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SEAT_CLICK2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_CANCEL_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_TICKET_UP:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_TICKET_UP2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_TICKET_DOWN:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_SCROLL_TICKET_DOWN2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_NEW_SEAT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_NEW_SEAT2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_MOVE_ITEM_LEFT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_SPLITBIND_MOVE_ITEM_RIGHT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;

                        /// <summary>
                        /// Errors that can occur on the time sheet page.
                        /// </summary>
                        case Error.EType.E_TSBIND_EXIT_BUTTON_CLICK:
                            ///If we lose the database this function could actually cause some issues.  We need to tell the user
                            ///to try the operation again.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system encountered a database communication problem and it is preventing the completion of the task that is related to the button you just pressed.   Please try the operation again.");
                            break;
                        case Error.EType.E_TSBIND_ROLE_CLICK:
                            ///Should only occur in development if at all.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to apply the function you called in this particular context.");
                            break;
                        case Error.EType.E_TSBIND_CLOCKIN_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to clock in.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_CLOCKOUT_CLICK:
                            ///This one should not occur.  It will happen only if a thread cannot be launched to clock the user out.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to clock out.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_PREPARE_FOR_SCREEN_CHANGE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An critical error occurred when trying to change screens.  This could cause system issues.");
                            break;
                        case Error.EType.E_TSBIND_CLOCKOUT_CURRENT_USER:
                            ///This can happen if the clock out attempt was not successful.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to clock out.  Please attempt the operation again.");
                            break;

                        case Error.EType.E_TSBIND_CALL_CLAIMDRAWER:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying claim the drawer.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_CALL_CLAIMDRAWER2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying claim the drawer.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_CALL_PRINTLASTCHECKOUT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to display the user's last checkout.  The issue could be related to either communication problems with the database or a printer if this KIOSK is configured with an attached printer.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_CALL_RELEASE_DRAWER:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to release the drawer.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_CALL_RELEASE_DRAWER2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to release the drawer.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_TSBIND_CALL_SETPASSWORD:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to set the user's magnetic swipe password.  Please attempt the operation again.");
                            break;
                        /// <summary>
                        /// Pages for system configuration.
                        /// </summary>
                        case Error.EType.E_PAGEEXMODGR_COMBOBOX_NAME_SELECTION_CHANGE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEDATATOOLS_INTERP_COMMAND:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occurred while attempting to process the last request.  Please try that operation again.");
                            break;
                        case Error.EType.E_PAGELOGIN_LOGIN_ATTEMPT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEMENUS_COMBOBOX_NAME_SEL_CHANGED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPAYMENTS_COMBOBOX_GW_TYPE_SEL_CHANGE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPRODUCTGROUPPRINTER_COMBOBOX_NAME_SELECTION_CHANGED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPRODUCTGROUPS_CB_NAME_SEL_CHANGED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPRODUCTGROUPS_RB_PROD_GROUPS_CHECKED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPRODUCTGROUPS_RB_EXCEPMODS_CHECKED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPRODUCTGROUPS_RB_PRICE_LEVELS_CHECKED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGEPRODUCTS_CB_NAME_SEL_CHANGED:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGESYSLOG_SCROLL_DOWN:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_PAGESYSLOG_SCROLL_UP:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered during the last operation.  If this problem persists exiting the system configuration screen and returning to this page could help resolve the issue if the database server is back on-line.");
                            break;
                        case Error.EType.E_SYSWINDOW_CANCEL_MOUSEDOWN:
                            ///If we get this one, the user could get stuck at the system window, but
                            ///not likely.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to exit the system configuration page.  This error is not typical.  If problems with the system persist, you may need to restart the application.");
                            break;
                        case Error.EType.E_SYSWINDOW_CANCEL:
                            ///Database context issues can cause this one.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered.  The application should continue to operate without error as long as the database connectivity restores itself.  Otherwise, it may be necessary to check to assure that the database server is functioning correctly.");
                            break;
                        case Error.EType.E_SYSWINDOW_RESET_CALLBACK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("A database connectivity error was encountered.  The application should continue to operate without error as long as the database connectivity restores itself.  Otherwise, it may be necessary to check to assure that the database server is functioning correctly.");
                            break;
                        case Error.EType.E_SYSWINDOW_LOGIN_CALLBACK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to login to the system configuration pages.  This is often a sign that the application was unable to contact the database server.  Please try again.");
                            break;
                        case Error.EType.E_SYSWINDOW_BOH_FUNC_BUTTON_CLICK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unknown error occurred while attempting to update this pages view.  Please try to navigate to the desired function again.");
                            break;

                        /// <summary>
                        /// Misc
                        /// </summary>
                        case Error.EType.E_PTIMEPUNCH_ADD_TIMEPUNCH:
                            ///Need to assure we tell the user about this error.  It probably means that their time punch was not logged.
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to add your time punch to the database.  This could be caused by a lack of communication from an unresponsive server.  Please inform your manager that you received this error to assure you are given credit for your shift and try again.");
                            break;
                        case Error.EType.E_SYNC_LISTEN_FOR_CLIENTS:
                            ///Do nothing here.  This function runs in the background and is based on legacy design.  It will be removed
                            ///from the system soon or I intend to remove it.
                            break;
                        case Error.EType.E_SCREENSAVER_UPDATE_IMAGE_LOCATION:
                            ///If the screen saver image is not moving properly we sure do want to know about it, but
                            ///we do not care to tell the user about it.  
                            break;

                        case Error.EType.E_CALL_POP_DRAWER1:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to open drawer 1.  Assure the printer is turned on and the cable connecting the drawer to the printer is locked in place. If there is no drawer connected to this terminal, then remove the connection at the system configuration window.");
                            break;

                        case Error.EType.E_CALL_POP_DRAWER2:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to open drawer 2.  Assure the printer is turned on and the cable connecting the drawer to the printer is locked in place. If there are not two drawers connected to this terminal, then remove the connection at the system configuration window.");
                            break;

                        ///Magnetic Card
                        case Error.EType.E_MAGCARD_AUTH:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occurred while communicating with the credit card processor.  Please attempt the transaction again.");
                            break;
                        case Error.EType.E_MAGCARD_RETURN_BY_ID:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occurred while communicating with the credit card processor.  Please attempt the transaction again.");
                            break;
                        case Error.EType.E_MAGCARD_CAPTURE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occurred while communicating with the credit card processor.  Please attempt the transaction again.");
                            break;
                        case Error.EType.E_MAGCARD_UNDO:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occurred while communicating with the credit card processor.  Please attempt the transaction again.");
                            break;

                        case Error.EType.E_MAGCARD_INIT:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occurred while communicating with the credit card processor.  This will most certainly cause issues when trying to process credit cards transactions.  The system will continue to retry until successful.");

                            break;
                        case Error.EType.E_REPORT_ERROR:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An error occured while attempting to generate the requested report.");
                            break;
                        /// <summary>
                        /// For the partial user page in the db library.
                        /// </summary>
                        case Error.EType.E_PUSER_CLOCKOUT_USER:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to add your time punch to the database.  This could be caused by a lack of communication from an unresponsive server.  Please inform your manager that you received this error to assure you are given credit for your shift and try again.");
                            break;
                        case Error.EType.E_PUSER_DO_CHECKOUT_TASK:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unexpected error occurred while trying to perform the employee checkout task.  This error was caused by a lack of database communication.  Please attempt the operation again.");
                            break;
                        case Error.EType.E_PSUER_GET_PAYMENTS_OBS_COLLECTION:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to retrieve all of the payments to be displayed in this view.  The cause of this error is related to a database communication error.  Please attempt the operation again.");
                            break;
                        ///Add Ons after the fact.
                        case Error.EType.E_INVALID_HOSTNAME_FORMAT: UMD.ShowGuiMessageSTASafe_NOTHROW("The host name of this KIOSK is not in the acceptable format.  The host name of every computer in the Oceanside network must begin with the \"KIOSK\" prefix and end with the KIOSK number.  For example KIOSK-0 would be the back office server host name, KIOSK-1 would be the master terminals host name.  You can configure this setting at the system configuration page that is now showing.");
                            break;
                        case Error.EType.E_HOST_NOT_DEFINED: UMD.ShowGuiMessageSTASafe_NOTHROW("When checking the valid hosts table, the system was unable to find a host name matching the host name of this KIOSK.  You can add an entry for " + KIOSK._cachedHostName + " at the system configuration page that is now showing.");
                            break;
                        case Error.EType.E_NODAYPART: UMD.ShowGuiMessageSTASafe_NOTHROW("There are no default dayparts defined in the system.  You must define at least one default daypart before you can use the system.  Examples of dayparts are breakfast, lunch and dinner.");
                            break;
                        case Error.EType.E_NOUSERS:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("There are no users defined in the configuration for this Oceanside system.  You can configure this setting at the system configuration page that is now showing.");
                            break;
                        case Error.EType.E_NOSYSTEM_CONFIG:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("There is no system configuration defined in the database.  You can configure this setting at the system configuration page that is now showing.");
                            break;
                        case Error.EType.E_NO_MENUS:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("There are no menus defined for this KIOSK.  You can configure this setting at the system configuration page that is now showing.");
                            break;
                    case Error.EType.E_PRINTSPOOL_PRINT:
                            {
                                bool couldRetry = false;
                                string specerror = e != null ? e.Message : "Unknown Exception";
                                if (extraParams != null)
                                {
                                    message = "An error occurred during a recent print transaction [" + specerror + "].  There may be a chance that the print job actually completed, but the printer failed to provide a response.  You can select another printer from the following list, or click on the \"X\" to ignore this error instance.";
                                    if (extraParams[0] is StringBuilder)
                                    {
                                        StringBuilder data = (extraParams[0] as StringBuilder);
                                        if (data != null)
                                        {
                                            couldRetry = true;

                                            //List<string> pNames = PrintSpool.GetAllPrinterNames();
                                            //RedirectPrinterOutput rdpo = 
                                            //    new RedirectPrinterOutput(pNames);
                                            //rdpo.SetMessage(message);
                                            //rdpo.ShowDialog();
                                            //if (RedirectPrinterOutput.LastResponse == UserResponse.YES)
                                            //{
                                            //   Oceanside.PrintSpool.PrintAsync(RedirectPrinterOutput.LastRedirectPrinter, data);
                                            //}
                                        }
                                    }
                                }
                                if (!couldRetry)
                                {
                                    message = "An error occurred during your last print request [" + specerror + "].  The error could have been related to a print job that was sent upto one minute ago.";
                                    UMD.ShowGuiMessageSTASafe_NOTHROW(message);
                                }
                            }
                            break;
                        case Error.EType.E_PRINTSPOOL_THREAD_START_ERROR:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("An unusual and unexpected error occurred while trying to print and the print job could not be started, please try again.  If this problem persists please contact your local dealer or try to reboot the printer in the meantime.");
                            break;
                        case Error.EType.E_PRINTSPOOL_OPEN_CASH_DRAWER:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to open the cash drawer at the printer you have configured for this KIOSK.");
                            break;
                        case Error.EType.E_PRINTSPOOL_LOGIN_TO_SHARE:
                            UMD.ShowGuiMessageSTASafe_NOTHROW("The system was unable to securely access the print server.  Please assure it's currently running.");
                            break;
                    }
                }
                catch
                {
                    ///We don't want to throw another error while logging an error.  Nothing we can do at this point.
                }
            }
        }
    }
}
